package com.atgm.mall.gmmailproduct.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.atgm.common.utils.GmMallUtils;
import com.atgm.mall.gmmailproduct.entity.AttrEntity;
import com.atgm.mall.gmmailproduct.entity.ProductAttrValueEntity;
import com.atgm.mall.gmmailproduct.service.ProductAttrValueService;
import com.atgm.mall.gmmailproduct.vo.AttrVo;
import com.atgm.mall.gmmailproduct.vo.resp.AttrRespVo;
import com.atgm.mall.gmmailproduct.vo.resp.GameAttrVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.atgm.mall.gmmailproduct.service.AttrService;
import com.atgm.common.utils.PageUtils;
import com.atgm.common.utils.R;



/**
 * 商品属性
 *
 * @author pdx
 * @email 945097967@qq.com
 * @date 2021-08-20 09:07:21
 */
@RestController
@RequestMapping("gmmallproduct/attr")
public class AttrController {
    @Autowired
    private AttrService attrService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        String key = (String) params.get("key");
        PageUtils page = null;
        if (GmMallUtils.isNotEmpty(key)) {
            page = attrService.queryPageCond(params);
        }else {
            page = attrService.queryPage(params);
        }

        return R.ok().setData(page);
    }

    @GetMapping("/info/{id}")
    public R getAttrInfo(@PathVariable("id") Long id) {
        AttrEntity attrEntity = attrService.getById(id);
        return R.ok().setData(attrEntity);
    }

    /**
     * 游戏商品属性信息
     */
    @GetMapping("/gameAttrInfo/{id}")
    public R info(@PathVariable("id") Long gameGoodsId) {
        List<GameAttrVo> gameAttrVos = attrService.queryGameGoodsAttrById(gameGoodsId);
        return R.ok().setData(gameAttrVos);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody AttrEntity attrEntity){
		attrService.saveAttr(attrEntity);
        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody AttrEntity attrEntity){
		attrService.updateAttr(attrEntity);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable("id") Long id){
        attrService.deleteAttrById(id);

        return R.ok();
    }

}
